from typing import List
class Solution:
    def findWhetherExistsPath(self, n: int, graph: List[List[int]], start: int, target: int) -> bool:
        # 构建邻接表
        link_table = [[] for _ in range(n)]
        for i, j in graph:
            link_table[i].append(j)
        print(link_table,'link_table')
        visted = [0]*n # 访问数组
        print(visted,'visted')
        # BFS
        que = [start]
        print(que,'que')
        while que:
            cur_node = que.pop()
            print(cur_node,'cur_node',link_table[cur_node],'link_table[cur_node]')
            if target in link_table[cur_node]: return True
            for node in link_table[cur_node]:
                if visted[node]==0:
                    que.insert(0,node)
                    print(que)
            visted[cur_node] = 1
        print(visted)
        return False

n = 5
graph = [[0, 1], [0, 2], [0, 4], [0, 4], [0, 1], [1, 3], [1, 4], [1, 3], [2, 3], [3, 4]]
start = 0
target = 3


# n = 3
# graph = [[0, 1], [0, 2], [1, 2], [1, 2]]
# start = 0
# target = 2

a = Solution()
print(a.findWhetherExistsPath(n,graph,start,target))